<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="Phone">
        <el-input v-model="form.phone" />
      </el-form-item>
      <el-form-item label="2fa">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">Login</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { TelegramClient } from 'telegram'
import { StringSession } from 'telegram/sessions'
export default {
  data() {
    return {
      form: {
        phone: "",
        password: ""
      }
    }
  },
  methods: {
    async onSubmit() {
      const API_ID = 123456 // put your API id here
      const API_HASH = 'abcdefg' // put your API hash here
      const SESSION = new StringSession('') //create a new StringSession, also you can use StoreSession
      const client = new TelegramClient(SESSION, API_ID, API_HASH, { connectionRetries: 5 })
      await client.connect() // Connecting to the server
      await client.sendCode({
        apiId: API_ID,
        apiHash: API_HASH
      },
        this.form.phone
      )
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}
</style>
